package cn.wjdiankong.levideo.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;

/**
 * Created by blue on 15-4-9.
 */
public class CircleClickRelativeLayout extends RelativeLayout {

    private CircleBtnHelper mHelper = null;

    public CircleClickRelativeLayout(Context context) {
        this(context, null);
    }

    public CircleClickRelativeLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        setWillNotDraw(false);

        mHelper = new CircleBtnHelper(this,false){
            @Override
            protected void onBackMaxCaled(float backMax) {
                backMaxCaled(backMax);
            }
        };
        mHelper.setDuration(380, 100, 600, 350);
        super.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
    }

    protected void backMaxCaled(float backMax){

    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        if(h > 0 && w > 0 && mHelper != null){
            mHelper.resetInitData(h,w);
        }
    }

    public CircleBtnHelper getCircleHelper(){
        return mHelper;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        boolean result = super.onInterceptTouchEvent(ev);
        return result;
    }

    @SuppressLint("ClickableViewAccessibility")
	@Override
    public boolean onTouchEvent(MotionEvent event) {
        boolean result = super.onTouchEvent(event);
        if(result){
            mHelper.handleClick(event);
        }
        return result;
    }

    @Override
    public void setOnClickListener(OnClickListener l) {
        mHelper.setOnClickListener(l);
    }

    @SuppressLint("WrongCall")
	@Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mHelper.onDraw(canvas);
    }



}
